package com.yami.shop.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yami.shop.bean.model.UserBehavior;
import org.apache.ibatis.annotations.Insert;

import java.util.List;

/**
 * @author DELL
 */
public interface UserBehaviorMapper extends BaseMapper<UserBehavior> {
    // 插入或更新行为权重（存在同类型行为则weight+1）
    @Insert("INSERT INTO user_behavior (user_id, item_id, behavior_type, weight, timestamp) " +
            "VALUES (#{userId}, #{itemId}, #{behaviorType}, 1, #{timestamp}) " +
            "ON DUPLICATE KEY UPDATE weight = weight + 1, timestamp = VALUES(timestamp)")
    boolean insertOrUpdate(UserBehavior behavior);

    List<UserBehavior> selectAll();
}
